package org.kaer.election.utils;

import android.graphics.Rect;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.RecyclerView.State;
import android.view.View;

/**
 * Created by lizj on 2016/7/26.
 */
public class GridItemDecoration extends RecyclerView.ItemDecoration {
    private int spanCount;
    private int space;

    public GridItemDecoration(int space, int spanCount) {
        this.space = space;
        this.spanCount = spanCount;
    }


    @Override
    public void getItemOffsets(Rect outRect, View view, RecyclerView parent, State state) {
        outRect.left = space;
        outRect.bottom = space;

        //由于每行都只有3个，所以第一个都是3的倍数，把左边距设为0
        if (parent.getChildLayoutPosition(view) % spanCount == 0) {
            outRect.left = 0;
        }
    }


}
